package com.macro.mall.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.TenantInfoDto;
import com.macro.mall.model.TenantEntity;
import com.macro.mall.service.TenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 *  商家管理controller
 */

@RestController
@Api(tags = "TenantController", description = "商家管理后台")
@RequestMapping("/tenant")
public class TenantController {

    @Autowired
    private TenantService tenantService;

    @ApiOperation(value = "查询商家信息info")
    @RequestMapping(value = "/findTenantInfo", method = RequestMethod.GET)
    public CommonResult findTenantInfo(HttpServletRequest request){
        String userName = String.valueOf(request.getAttribute("useName"));
        TenantEntity tenantInfo = tenantService.findTenantInfo(userName);
        return CommonResult.success(tenantInfo);
    }

    @ApiOperation(value = "修改商家信息info")
    @RequestMapping(value = "/updateTenantInfo", method = RequestMethod.POST)
    public CommonResult updateTenantInfo(@RequestBody TenantInfoDto tenantInfoDto){
        tenantService.updateTenantInfo(tenantInfoDto);
        return  CommonResult.success(null);
    }

}
